local M = _G.ClientOHOH.class.new(script,_G.ClientOHOH.files.Client_PlayerComponent(),script.Parent.Name)
local ClientOHOH = _G.ClientOHOH
local PlayerInfoGui = ClientOHOH.load.UIManager():CreateUI("PlayerInfoGui",require(script.PlayerInfoGui))
local CallBackManager = ClientOHOH.load.CallBackManager();
local EventList = ClientOHOH.load.EventList();
local FunctionList = ClientOHOH.load.FunctionList();
function M.new(self,...)
    return M(self,...)
end

function M.ctor(self,parent)
    M.super.ctor(self,parent)
    self.DataStore = self.parent:GetComponent(_G.ClientOHOH.load.Client_PlayerDataComponent())
    self.AttributeCtrl = self.parent:GetComponent(_G.CommonOHOH.load.Common_CarInfoCtrl())
    self.player = parent
    self:UpdateUi()
    
    self.AttributeCtrl.UpdateEvent:Connect(function()
        self:UpdateUi()
    end)

    PlayerInfoGui:Show()
    -- self:AddConnect()
end

function M.UpdateUi(self)
    local maxHp = self.AttributeCtrl:GetMaxHp()
    local hp = self.AttributeCtrl:GetHp()
    local attack = self.AttributeCtrl:GetAttack()
    local propulsion = self.AttributeCtrl:GetPropulsion()
    PlayerInfoGui:Update(maxHp,hp,attack,propulsion)
end


-- self.UpdateEvent


function M.AddConnect(self)
    --监听hp，attack，propulsion数值变化更新
    self.parent:AttributeValueChanged("Hp",function()
        local maxHp = self.AttributeCtrl:GetMaxHp()
        local hp = self.AttributeCtrl:GetHp()
        PlayerInfoGui:UpdateHp(maxHp,hp)
    end)

    self.parent:AttributeValueChanged("MaxHp",function()
        local maxHp = self.AttributeCtrl:GetMaxHp()
        local hp = self.AttributeCtrl:GetHp()
        PlayerInfoGui:UpdateHp(maxHp,hp)
    end)

    self.parent:AttributeValueChanged("Propulsion",function()
        local propulsion = self.AttributeCtrl:GetPropulsion()
        PlayerInfoGui:UpdatePropulsion(propulsion)
    end)
    self.parent:AttributeValueChanged("Attack",function()
        local attack = self.AttributeCtrl:GetAttack()
        PlayerInfoGui:UpdateAttack(attack)
    end)
end



function M.dtor(self)
    M.super.dtor(self)
end


return M 